import Vue from "vue";
import VueRouter from "vue-router";

import layout from "@/layout/index.vue";
Vue.use(VueRouter);
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};
const originalReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch((err) => err);
};
const routes = [
  {
    path: "/",
    redirect: "/home",
    component: layout,
    hidden: false,
    children: [
      {
        path: "home",
        component: () => import("@/views/Home.vue"),
        meta: { title: "首页", icon: "icon iconfont icon-xie" },
      },
    ],
  },

  {
    path: "/FileTakeNumber",
    component: layout,
    redirect: "/FileTakeNumber/FileTakeNumber",
    hidden: true,
    children: [
      {
        path: "FileTakeNumber",
        name: "FileTakeNumber",
        component: () => import("../views/FileTakeNumber/FileTakeNumber.vue"),
        meta: { title: "主文件取号", icon: "icon iconfont icon-xie" },
      },
    ],
  },

  {
    path: "/manuscript",
    component: layout,
    hidden: true,
    redirect: "/manuscript/manuscript",
    children: [
      {
        path: "manuscript",
        name: "manuscript",
        component: () => import("../views/manuscript/manuscript.vue"),
        meta: { title: "草稿箱", icon: "icon iconfont icon-sousuo" },
      },
    ],
  },

  {
    path: "/workflow",
    component: layout,
    hidden: true,
    redirect: "/workflow/workflow",
    children: [
      {
        path: "workflow",
        name: "workflow",
        component: () => import("../views/workflow/workflow.vue"),
        meta: { title: "工作流", icon: "icon iconfont icon-lianjie1" },
      },
    ],
  },

  {
    path: "/FileForDetails",
    component: layout,
    hidden: true,
    redirect: "/FileForDetails/FileForDetails",
    children: [
      {
        path: "FileForDetails",
        name: "FileForDetails",
        component: () => import("../views/filesearch/FileForDetails.vue"),
        meta: { title: "报表", icon: "icon iconfont icon-chengshibujian" },
      },
    ],
  },

  {
    path: "/filesearch",
    component: layout,
    hidden: true,
    redirect: "/filesearch/filesearch",
    children: [
      {
        path: "filesearch",
        name: "filesearch",
        component: () => import("../views/filesearch/filesearch.vue"),
        meta: { title: "文件查询", icon: "icon iconfont icon-sousuo" },
      },
    ],
  },

  {
    path: "/FullTextRetrieval",
    component: layout,
    hidden: true,
    redirect: "/FullTextRetrieval/FullTextRetrieval",
    children: [
      {
        path: "FullTextRetrieval",
        name: "FullTextRetrieval",
        component: () =>
          import("../views/FullTextRetrieval/FullTextRetrieval.vue"),
        meta: { title: "全文检索", icon: "icon iconfont icon-sousuo" },
      },
    ],
  },

  {
    path: "/DownloadTemplate",
    component: layout,
    hidden: true,
    redirect: "/DownloadTemplate/DownloadTemplate",
    children: [
      {
        path: "DownloadTemplate",
        name: "DownloadTemplate",
        component: () =>
          import("../views/DownloadTemplate/DownloadTemplate.vue"),
        meta: { title: "模板下载", icon: "icon iconfont icon-mobanxiazai" },
      },
    ],
  },

  {
    path: "/MarkMaintain",
    component: layout,
    hidden: true,
    redirect: "/MarkMaintain/MarkMaintain",
    children: [
      {
        path: "MarkMaintain",
        name: "MarkMaintain",
        component: () => import("../views/sublevel/MarkMaintain.vue"),
        meta: { title: "方案标志维护", icon: "icon iconfont icon-mobanxiazai" },
      },
    ],
  },

  {
    path: "/MyFavorite",
    component: layout,
    hidden: true,
    redirect: "/MyFavorite/MyFavorite",
    children: [
      {
        path: "MyFavorite",
        name: "MyFavorite",
        component: () => import("../views/MyFavorite/MyFavorite.vue"),
        meta: { title: "我的收藏", icon: "icon iconfont icon-shoucang" },
      },
    ],
  },

  {
    path: "/manage",
    component: layout,
    hidden: true,
    // meta: { title: "管理界面" },
    redirect: "/manage/manage",
    children: [
      {
        path: "manage",
        name: "manage",
        component: () => import("../views/manage/manage.vue"),
        meta: {
          title: "管理界面",
          affix: true,
          icon: "icon iconfont icon-mouse",
        },
      },
    ],
  },

  {
    path: "/FileForDetails",
    name: "FileForDetails",
    component: () => import("../views/filesearch/FileForDetails.vue"),
    meta: { title: "文件详情" },
  },
  // {
  //   path: "/MarkMaintain",
  //   name: "MarkMaintain",
  //   component: () => import("../views/sublevel/MarkMaintain.vue"),
  //   meta: { title: "标志维护", affix: true },
  // },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

router.beforeEach((to, from, next) => {
  document.title = to.meta.title;
  next();
});

export default router;
